package org.s3.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.s3.project.entity.Comment;


import org.s3.project.entity.addComment;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfx
 * @version 1.0
 * @Description
 * @date 2025/2/9 9:39
 */
@Mapper
@Repository
public interface CommentMapper extends BaseMapper<Comment> {
    /**
     * @param id 评论id
     * @return
     */
    //根据id查询评论
    @Select(" select c.id, c.Comment, c.titile, c.score\n" +
            "        from `comment` c,\n" +
            "             dish d\n" +
            "        where c.Dish_id = d.id\n" +
            "          and c.status=1\n"+
            "          and c.id = #{id}")
    List<Comment> getCommentById(@Param("id") Integer id);

    //批量新增评论表
    Boolean insertComments(@Param("list") List<Comment> comment);


    List<Comment> selectCommentLike(@Param("Mname")String Mname,@Param("Uname")String Uname,@Param("created_time")String created_time, @Param("create_timeOne")String createTimeOne);

    /**
     *
     * 删除单个评论
     * @param id 评论id
     * @return 删除结果
     */
    @Delete("delete from `comment` where id = #{id}")
    int deleteComment(int id);
    /**
     * 批量删除评论
     * @param ids 评论id数组
     */
    int deleteCommentIds(int[] ids);

    /**
     * 根据用户id查询所有评论
     *
     * @param User_id 用户id
     * @return
     */
    @Select("select c.id,d.name, c.Comment, c.score,c.status\n" +
            "        from `comment` c,\n" +
            "             dish d,\n" +
            "             `user` u\n" +
            "        where c.Dish_id = d.id\n" +
            "          and c.User_id = u.id\n"+
            "          and c.status=1\n" +
            "          and c.User_id = #{User_id}")
    List<Comment> getCommentByUserId(@Param("User_id") Integer User_id);
}
